//
//  ZSY_TravelTwelveTableViewCell.m
//  ZSY_BreadTrip
//
//  Created by 张诗宇 on 15/12/30.
//  Copyright © 2015年 张诗宇. All rights reserved.
//

#import "ZSY_TravelTwelveTableViewCell.h"

@interface ZSY_TravelTwelveTableViewCell ()

@property (nonatomic, retain) ZSY_BaseImageView *coverImageView;
@property (nonatomic, retain) ZSY_BaseLabel *nameLabel;
@property (nonatomic, retain) ZSY_BaseLabel *lastDayLabel;
@property (nonatomic, retain) ZSY_BaseLabel *dayCount;
@property (nonatomic, retain) ZSY_BaseLabel *viewCount;
@property (nonatomic, retain) ZSY_BaseLabel *placeLabel;
@property (nonatomic, retain) ZSY_BaseImageView *avatarImageView;
@property (nonatomic, retain) ZSY_BaseLabel *userNameLabel;

@property (nonatomic, retain) ZSY_BaseView *view;

@end

@implementation ZSY_TravelTwelveTableViewCell

- (void)dealloc {
    [_coverImageView release];
    [_nameLabel release];
    [_lastDayLabel release];
    [_dayCount release];
    [_viewCount release];
    [_placeLabel release];
    [_avatarImageView release];
    [_userNameLabel release];
    [_view release];
    [super dealloc];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (void)setTwelve:(ZSY_TwelveType *)twelve {
    if (_twelve != twelve) {
        [_twelve release];
        _twelve = [twelve retain];
    NSURL *coverUrl = [NSURL URLWithString:_twelve.cover_image_w640];
    [self.coverImageView sd_setImageWithURL:coverUrl placeholderImage:nil];
    /**
     *  标题赋值
     */
    self.nameLabel.text = _twelve.index_title;
    self.nameLabel.textColor = [UIColor whiteColor];
    self.nameLabel.frame = CGRectMake(15, 10, WIDTH - 50, 20);
    self.nameLabel.font = [UIFont systemFontOfSize:18];
    self.nameLabel.numberOfLines = 0;
    [self.nameLabel sizeToFit];
    self.nameLabel.lineBreakMode = NSLineBreakByWordWrapping;
    /**
     *  时间赋值
     */
    self.lastDayLabel.frame = CGRectMake(25, self.nameLabel.frame.size.height + 15, 40, 10);
    self.lastDayLabel.text = _twelve.last_day;
    self.lastDayLabel.textColor = [UIColor whiteColor];
    [self.lastDayLabel sizeToFit];
    self.lastDayLabel.font = [UIFont systemFontOfSize:8];
    self.lastDayLabel.font = [UIFont boldSystemFontOfSize:9];
    /**
     *  图标
     */
    self.view.frame = CGRectMake(15, self.nameLabel.frame.size.height + 16, 3, 9);
    self.view.layer.cornerRadius = 1;
    self.view.layer.masksToBounds = YES;
    
    /**
     天数赋值
     */
    self.dayCount.frame = CGRectMake(self.lastDayLabel.frame.size.width + 25 + 10, self.nameLabel.frame.size.height + 15, 10, 10);
    self.dayCount.text = [NSString stringWithFormat:@"%@故事", _twelve.spot_count];
    self.dayCount.textColor = [UIColor whiteColor];
    self.dayCount.font = [UIFont systemFontOfSize:8];
    self.dayCount.font = [UIFont boldSystemFontOfSize:9];
    [self.dayCount sizeToFit];
    /**
     *  浏览次数赋值
     */
    self.viewCount.frame = CGRectMake(self.lastDayLabel.frame.size.width + self.dayCount.frame.size.width + 25 + 5 + 15, self.nameLabel.frame.size.height + 15, 40, 10);
    self.viewCount.text = [NSString stringWithFormat:@"%@次浏览", _twelve.view_count];
    self.viewCount.textColor = [UIColor whiteColor];
    [self.viewCount sizeToFit];
    self.viewCount.font = [UIFont systemFontOfSize:8];
    self.viewCount.font = [UIFont boldSystemFontOfSize:9];

    /**
     *  头像赋值
     *
     *  @return
     */
    NSURL *avaUrl = [NSURL URLWithString:_twelve.userModel.avatar_m];
    [self.avatarImageView sd_setImageWithURL:avaUrl placeholderImage:nil];
    /**
     *  userName 赋值
     *
     *  @return
     */
    self.userNameLabel.textColor = [UIColor whiteColor];
    self.userNameLabel.text = [NSString stringWithFormat:@"by %@",_twelve.userModel.name];
    self.userNameLabel.font = [UIFont systemFontOfSize:10];
    self.userNameLabel.font = [UIFont boldSystemFontOfSize:9];
    [self.userNameLabel sizeToFit];
    }
    

}



- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubview];
    }
    return self;
}

- (void)createSubview {
//    self.contentView.backgroundColor = [UIColor colorWithRed:248 / 255.0 green:243 / 255.0 blue:233 / 255.0 alpha:1];

    /**
     背景图片
     
     - returns:
     */
    self.coverImageView = [[ZSY_BaseImageView alloc] initWithFrame:CGRectMake(10, 10, WIDTH - 20, 200)];
    self.coverImageView.backgroundColor = [UIColor lightGrayColor];
    self.coverImageView.layer.cornerRadius = 5;
    self.coverImageView.layer.masksToBounds = YES;
    self.coverImageView.layer.borderWidth = 1;
    self.coverImageView.layer.borderColor = [UIColor lightGrayColor].CGColor;

    [self.contentView addSubview:_coverImageView];
    
    /**
     图片上的标题
     
     - returns:
     */
    self.nameLabel = [[ZSY_BaseLabel alloc] initWithFrame:CGRectMake(15, 10, WIDTH - 50, 20)];
//    self.nameLabel.backgroundColor = [UIColor greenColor];
    [self.coverImageView addSubview:_nameLabel];
    [_nameLabel release];
    
    /**
     *  时间label
     */
    self.lastDayLabel = [[ZSY_BaseLabel alloc] initWithFrame:CGRectMake(25, self.nameLabel.frame.size.height + 15, 40, 10)];
//    self.lastDayLabel.backgroundColor = [UIColor orangeColor];
    [self.coverImageView addSubview:_lastDayLabel];
    [_lastDayLabel release];
    /**
     图标
     
     - returns:
     */
    self.view = [[ZSY_BaseView alloc] init];
    self.view.backgroundColor = [UIColor cyanColor];
    [self.coverImageView addSubview:_view];
    [_view release];
    
    /**
     *  天数label
     */
    self.dayCount = [[ZSY_BaseLabel alloc] initWithFrame:CGRectMake(self.lastDayLabel.frame.size.width + 25 + 10, self.nameLabel.frame.size.height + 15, 10, 10)];
//    self.dayCount.backgroundColor = [UIColor cyanColor];
    [self.coverImageView addSubview:_dayCount];
    [_dayCount release];
    /**
     *  浏览次数label
     */
    self.viewCount = [[ZSY_BaseLabel alloc] initWithFrame:CGRectMake(self.lastDayLabel.frame.size.width + self.dayCount.frame.size.width + 25 + 5 + 15, self.nameLabel.frame.size.height + 15, 40, 10)];
//    self.viewCount.backgroundColor = [UIColor yellowColor];
    [self.coverImageView addSubview:_viewCount];
    [_viewCount release];
//    /**
//     *  地点label
//     */
//    self.placeLabel = [[ZSY_BaseLabel alloc] initWithFrame:CGRectMake(25, self.nameLabel.frame.size.height + 10 + self.viewCount.frame.size.height + 7, 40, 10)];
//    self.placeLabel.backgroundColor = [UIColor redColor];
//    [self.coverImageView addSubview:_placeLabel];
//    [_placeLabel release];
    /**
     *  头像图标
     */
    self.avatarImageView = [[ZSY_BaseImageView alloc] initWithFrame:CGRectMake(15, 200 - 45, 30, 30)];
    self.avatarImageView.layer.cornerRadius = 15;
    self.avatarImageView.layer.masksToBounds = YES;
//    _avatarImageView.backgroundColor = [UIColor blackColor];
    [self.coverImageView addSubview:_avatarImageView];
    [_avatarImageView release];
    /**
     *  用户名字label
     */
    self.userNameLabel = [[ZSY_BaseLabel alloc] initWithFrame:CGRectMake(15 + self.avatarImageView.frame.size.width + 5, 200 - 35, 100, 10)];
//    self.userNameLabel.backgroundColor = [UIColor blueColor];
    [self.coverImageView addSubview:_userNameLabel];
    [_userNameLabel release];
    [_coverImageView release];

}

@end
